<template>
  <default-home-card icon="BarChartOutlined" title="考试总览">
    <div class="echarts-box">
      <div class="gradient-main" id="gradient-main"></div>
    </div>
  </default-home-card>
</template>
<script setup>
  import DefaultHomeCard from '/@/views/system/home/components/default-home-card.vue';
  import * as echarts from 'echarts';
  import { onMounted, reactive } from 'vue';
  import { basecountApi } from '/@/api/business/exam/basecount-api.js';

  const data = reactive({
    lista: [],
    listb: [],
  });
  onMounted(() => {
    basecountApi
      .examcount()
      .then((res) => {
        res.data.forEach((item) => {
          data.lista.push(item.beginDate);
          data.listb.push(item.num);
        });
      })
      .finally(() => {
        init();
      });
  });

  function init() {
    let option = {

      tooltip: {
        // 是否显示提示框
        show: true,
        // 触发类型，axis 移动到坐标轴就触发
        trigger: 'axis',
      },
      legend: {
        // 图例的数据数组，
        data: ['用户数量'],
      },
      xAxis: {
        type: 'category',
        data: data.lista,
      },
      yAxis: {
        type: 'value',
        axisLabel:{
          formatter:"{value} "
        }
      },
      series: [
        {

          name: '用户数量',
          data: data.listb,
          type: 'line',
          smooth: false,
          itemStyle: {
            borderRadius: 10,
            borderColor: '#ffffff',
            borderWidth: 2,
          },
          markPoint:{
            data:[
              {type:"max",name:"最大值"},
              {type:"min",name:"最小值"},
            ]
          },
          // 图线标注
          markLine:{
            data:[{type:"average",name:"平均值"}]
          }

        },
      ],
    };

    let chartDom = document.getElementById('gradient-main');
    if (chartDom) {
      let myChart = echarts.init(chartDom);
      option && myChart.setOption(option);
    }
  }
</script>
<style lang="less" scoped>
  .echarts-box {
    display: flex;
    align-items: center;
    justify-content: center;

    .gradient-main {
      width: 2000px;
      height: 400px;
      background: #fff;
    }
  }
</style>
